// Copyright (c) 2011 Blue Onion Software, All rights reserved
using System;
using System.Xml.Serialization;

namespace BlueOnionSoftware.Bloget
{
    [XmlRoot(ElementName = "Content")]
    public class Content
    {
        private string _text = string.Empty;
        private DateTime _lastUpdate = DateTime.UtcNow;
        private string _sourceTitle = string.Empty;
        private string _sourceLink = string.Empty;
        private CommentCollection _comments = new CommentCollection();
        private ReferenceCollection _references = new ReferenceCollection();
        private AttachmentCollection _attachments = new AttachmentCollection();

        public Content()
        {
        }

        internal Content(Content content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            _text = content._text;
            _lastUpdate = content._lastUpdate;
            _sourceTitle = content._sourceTitle;
            _sourceLink = content._sourceLink;
            _comments = new CommentCollection(content._comments);
            _references = new ReferenceCollection(content._references);
            _attachments = new AttachmentCollection(content._attachments);
        }

        [XmlElement("text")]
        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }

        [XmlElement("last_update")]
        public DateTime LastUpdate
        {
            get { return _lastUpdate; }
            set { _lastUpdate = value; }
        }

        [XmlElement("source_title")]
        public string SourceTitle
        {
            get { return _sourceTitle; }
            set { _sourceTitle = value; }
        }

        [XmlElement("source_link")]
        public string SourceLink
        {
            get { return _sourceLink; }
            set { _sourceLink = value; }
        }

        [XmlArray("comments")]
        [XmlArrayItem("comment", typeof (Comment))]
        public CommentCollection Comments
        {
            get { return _comments; }
        }

        [XmlArray("references")]
        [XmlArrayItem("reference", typeof (Reference))]
        public ReferenceCollection References
        {
            get { return _references; }
        }

        [XmlArray("attachments")]
        [XmlArrayItem("attachment", typeof (Attachment))]
        public AttachmentCollection Attachments
        {
            get { return _attachments; }
        }
    }
}